#include "include/comment.h"
#include "include/clock.h"
#include "include/keyboard.h"
#include <string.h>

static	CLOCKMSG *clock_msg;

static	KEYBOARDMSG *keyboard_msg;
static	KEYBOARDBUFF *keyboard_buff;
static	KEYBOARDPOS	*keyboard_pos;

void shell_install(const void *addr_time, const void *addr_keyboard)
{
	int i;

	clock_msg  = (CLOCKMSG *)addr_time;

	keyboard_msg = (KEYBOARDMSG *)addr_keyboard;
	keyboard_buff = (KEYBOARDBUFF *)((int)keyboard_msg + sizeof(KEYBOARDMSG));
	keyboard_pos = (KEYBOARDPOS *)((int)keyboard_buff + sizeof(KEYBOARDBUFF));
	keyboard_pos -> pb = 23;
	keyboard_pos -> pp = 9;
	puts_ex(23, 0, " BXT@OS:#");

	//	arch
	for(i = 0; i < 80; i++)
	{
		putc_ex(1, i, '-');
	}
	for(i = 0; i < 80; i++)
	{
		putc_ex(22, i, '=');
	}

	//	Hello word
	puts_ex(2, 30, "Welcome to my system");
	puts_ex(4, 37, "BXT-OS");

}

static char shell_message_array[64] = {0};

void Message();

void shell_run()
{
	if(0 == strcmp("show", shell_message_array))
	{
		Message();
	}

	//memset(shell_message_array, 0, 64);
}

void send_message_shell(const char *message)
{
	memcpy(shell_message_array, message, 64);
}

void Message()
{
	switch(clock_msg -> s % 4)
	{
		case 0:
			{
				puts_ex(9, 6, "                                ");
				puts_ex(7, 4, "Powered by: BXT-KeZhan");
			}
			break;
		case 1:
			{
				puts_ex(11, 8, "                 ");
				puts_ex(9, 6, "BBS URL: http://www.bxtkezhan.cc");
			}
			break;
		case 2:
			{
				puts_ex(13, 10, "                    ");
				puts_ex(11, 8, "QQ qun: 313504382");
			}
			break;
		case 3:
			{
				puts_ex(7, 4, "                      ");
				puts_ex(13, 10, "Author: BXT(Lindorl)");
			}
			break;

		default:
			break;
	}
}
